package JDBC1;

import java.sql.*;

/*public class JdbcTest {
    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        Class.forName("com.mysql.jdbc.Driver");
        Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/Lib","root","123456");
        //查询books
        String sql="SELECT *\n" +
                "FROM books";
        Statement statement =connection.createStatement();
        ResultSet resultSet = statement.executeQuery(sql);
        while(resultSet.next()){
            int BookID =resultSet.getInt("BookID");
            String title=resultSet.getNString("title");
            String Author =resultSet.getString("Author");
            String TypeName= resultSet.getString("TypeName");
            String publisher = resultSet.getNString("publisher");
            System.out.println("BookID="+ BookID + " title="+ title + " Author ="+ Author+"TypeName ="+TypeName+"publisher="+publisher);
        }
        resultSet.close();
        statement.close();
        connection.close();
    }
}*/

/*class shanchu {
    //删除一列数据
    public static void main(String[] args) throws ClassNotFoundException, SQLException {
            Class.forName("com.mysql.jdbc.Driver");
            Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/Lib", "root", "123456");
            String sql = "DELETE FROM  `books`WHERE `BookID`=70";
            Statement statement = connection.createStatement();
        int i=statement.executeUpdate(sql);
        System.out.println("删除数据量:"+i);
        statement.close();
        connection.close();
    }
}*/



/*class xuigai {
    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        Class.forName("com.mysql.jdbc.Driver");
        Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/Lib", "root", "123456");
        Statement statement = connection.createStatement();
        String title1 = "mysql";
        String sql = "UPDATE books SET `title`='" + title1 + "'WHERE `BookID`=59";
        int n=statement.executeUpdate(sql);
        System.out.println(n);
        connection.close();
        statement.close();
    }
}*/

class tianjia{
    public static void main(String[] args) throws SQLException, ClassNotFoundException {
        Class.forName("com.mysql.jdbc.Driver");
        Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/Lib", "root", "123456");
        String sql="INSERT IGNORE INTO`books`(`BookID`,`title`,`Author`,`TypeName`,`publisher`)" +
                " VALUES (63,'SQL server 2014数据库应用技术','钱冬云','TP323','清华大学出版社'),(63,'SQL server 2014数据库应用技术','钱冬云','TP323','清华大学出版社')";
        Statement statement = connection.createStatement();

        int resultSet = statement.executeUpdate(sql);
        System.out.println(resultSet);
        statement.close();
        connection.close();

    }
}
